package code.android.MiracleWalker.view;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.text.style.TypefaceSpan;
import android.util.AttributeSet;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;

public class TimerView extends View {
	String text = "";
	Paint paint = new Paint();
	public static final float DEFAULT_SIZE = 20.0f;
	
	
	Context mContext = null;
	private String hint = null;
	
	public TimerView(Context context) {
		super(context);
		init(context);
	}
	
  	public TimerView(Context  context, AttributeSet  attrs) {
  		super(context, attrs);
		init(context);
  	}
	
	public TimerView(Context  context, AttributeSet  attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	private void init(Context context) {
		Typeface tf = Typeface.createFromAsset(context.getAssets(), "ydsho.ttf");
		paint.setTypeface(tf);
		paint.setARGB(0xff, 0x9e, 0x92, 0x92);
		paint.setTextSize(DEFAULT_SIZE);
		paint.setAntiAlias(true);
		paint.setLinearText(true);
		mContext = context;
	}
	
	public void setTextSize(int size) {
		paint.setTextSize(size);
	}
	
	public void setHint(String hint) {
		this.text = hint;
		postInvalidate();
	}

	public void update(String str) {
		this.text = str;
	}
	
	@Override
	protected void onDraw(Canvas canvas) {
		canvas.drawText(this.text, 0, 50, paint);
		super.onDraw(canvas);
	}
	
	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		Display display = ((WindowManager)mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
		setMeasuredDimension(display.getWidth(), 60);
	}
}
